package cn.tedu.charging.order.dao.repository.impl;

import cn.tedu.charging.order.dao.mapper.OrderFailMapper;
import cn.tedu.charging.order.dao.mapper.OrderSuccessMapper;
import cn.tedu.charging.order.dao.repository.OrderRepository;
import cn.tedu.charging.order.pojo.po.ChargingOrderFilePO;
import cn.tedu.charging.order.pojo.po.ChargingOrderSuccessPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
@Slf4j
public class OrderRepositoryImpl implements OrderRepository {
    @Autowired
    private OrderSuccessMapper orderSuccessMapper;
    @Autowired
    private OrderFailMapper orderFailMapper;
    @Override
    public ChargingOrderSuccessPO getOrderSuccess(String orderNo) {
        log.debug("根据订单号查询订单成功记录,订单号:{}",orderNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("bill_id",orderNo);
        log.debug("查询条件:{}",queryWrapper);
        return orderSuccessMapper.selectOne(queryWrapper);
    }

    @Override
    public ChargingOrderFilePO getOrderFile(String orderNo) {
        log.debug("根据订单号查询订单失败记录,订单号:{}",orderNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("bill_id",orderNo);
        log.debug("查询条件:{}",queryWrapper);
        return orderFailMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer insertOrderFile(ChargingOrderFilePO chargingOrderFilePO) {
        log.debug("保存因设备无响应的订单失败记录:{}",chargingOrderFilePO);
        return orderFailMapper.insert(chargingOrderFilePO);
    }
}
